#ifndef TABLEDIALOG_H
#define TABLEDIALOG_H

#include <QDialog>
#include <QLabel>
#include <QSpinBox>
#include <QPushButton>

class TableSelectionWidget : public QWidget
{
    Q_OBJECT

public:
    explicit TableSelectionWidget(QWidget *parent = nullptr);

signals:
    void sizeSelected(int rows, int columns);
    void selectionConfirmed(int rows, int columns); // 触发直接生成表格
    void hoverSizeChanged(int rows, int columns); // 新增信号用于动态更新显示的尺寸

protected:
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;

private:
    void updateSelection(const QPoint &pos);
    int m_rows;
    int m_columns;
    int m_hoveredRows;
    int m_hoveredColumns;
};

class TableDialog : public QDialog
{
    Q_OBJECT

public:
    explicit TableDialog(QWidget *parent = nullptr);
    int rows() const;
    int columns() const;

private slots:
    void updateSizeLabel(int rows, int columns);
    void updateHoverSizeLabel(int rows, int columns); // 新增槽函数用于动态更新标签


private:
    TableSelectionWidget *selectionWidget;
    QLabel *sizeLabel;
    int m_rows = 1;
    int m_columns = 1;
};

#endif // TABLEDIALOG_H
